package com.zb.user.controller;


import com.zb.annotation.SystemLog;
import com.zb.constant.OperationLogModuleType;
import com.zb.constant.OperationLogType;
import com.zb.entity.SelectVo;
import com.zb.result.Result;
import com.zb.service.ZjUserTypeService;
import com.zb.user.service.ConUserService;
import com.zb.utils.TokenUtil;
import com.zb.vo.UserTypeSelectVo;
import com.zb.vo.UserTypeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 用户分类表 前端控制器
 * </p>
 *
 * @author WEN
 * @since 2023-08-08
 */
@Api(tags = "用户分类接口")
@RestController
@RequestMapping("/user/type")
public class ZjUserTypeController {
    @Resource
    private ZjUserTypeService userTypeService;
    @Resource
    private ConUserService conUserService;

    @SystemLog(moduleType = OperationLogModuleType.USER_MODULE_TYPE, type = OperationLogType.INSERT_UPDATE, remark = "用户档案 - 新增或修改用户分类")
    @ApiOperation("新增或修改用户分类")
    @PostMapping("/save")
    public Result save(HttpServletRequest request, UserTypeVo typeVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        userTypeService.save(custAccId, typeVo);
        return Result.success(null == typeVo.getId()? "新增分类成功" : "修改分类成功");
    }

    @SystemLog(moduleType = OperationLogModuleType.USER_MODULE_TYPE, type = OperationLogType.SELECT, remark = "用户档案 - 获取用户分类列表")
    @ApiOperation("获取用户分类列表")
    @PostMapping("/getList")
    public Result getList(HttpServletRequest request, @RequestBody UserTypeSelectVo selectVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        return Result.success("获取用户分类列表成功").data(userTypeService.getList(custAccId, selectVo));
    }

    @SystemLog(moduleType = OperationLogModuleType.USER_MODULE_TYPE, type = OperationLogType.SELECT, remark = "用户档案 - 批量更改用户分类状态")
    @ApiOperation("批量更改用户分类状态")
    @PutMapping("/")
    public Result disable(@RequestParam @ApiParam(value = "分类状态：false-启用，true-禁用", required = true, example = "false") boolean status,
                          @RequestBody @ApiParam(value = "分类ID集合", required = true) List<Long> idList) {
        userTypeService.updateBatchDisabledByIds(idList, status);
        return Result.success(status? "禁用分类成功" : "启用分类成功");
    }

    @SystemLog(moduleType = OperationLogModuleType.USER_MODULE_TYPE, type = OperationLogType.SELECT, remark = "用户档案 - 批量删除用户分类")
    @ApiOperation("批量删除用户分类")
    @DeleteMapping("/")
    public Result delete(@RequestBody @ApiParam(value = "分类ID集合", required = true) List<Long> idList) {
        conUserService.deleteTypeBatchById(idList);
        return Result.success("删除分类成功");
    }



}
